// ----------------权益中心插件相关-----------------------------------
// var activePar=[{'ename':'abcdasdfasd','poolID':'1234'},{'ename':'waerwerqdsadf','poolID':'76878'}];   //储存活动ename与poolID
var activePar=[];   //储存活动ename与poolID
//引入插件
const plugintask = requirePlugin("taskPlugin")
var plugin = requirePlugin("myPlugin");
//这个bridge用于和插件进行数据通信
const bridge = {
  bizCode:"3000000038850063",
  getCheckBenefitID({ ename, poolID }) {
    let isfind=false;
    activePar.map(v=>{ 
      v.ename==ename && (isfind=true)
    })
    !isfind && activePar.push({"ename":ename,"poolID":poolID})
    ename && my.alert({content:'成功获取活动信息，可继续选择其他活动，或者点击左上角返回。'})
    // my.alert({ content: ename });
    // my.alert({content:JSON.stringify(activePar)})
    console.log(poolID, ename);
    // c
    // my.alert({ content: poolID });
  }
}
// ----------------权益中心插件相关-----------------------------------

const { cloud } = getApp();



Page({

    data:{
    tapData:[],
    // couponA:'',
    // couponB:'',
    // couponC:'',
    // couponD:'',
    },
  onLoad(query) {
      console.log('onLoad:plugin.setBridge(bridge)-----'+JSON.stringify(bridge))
      // my.alert({content:'onLoad:plugin.setBridge(bridge)-----'+JSON.stringify(bridge)})
      plugin.setBridge(bridge); 
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
  },

       getUserNick() {
        my.authorize({
          scopes: 'scope.userInfo',
          success: (res) => {
        my.getAuthUserInfo({
          success: (userInfo) => {
            console.log(userInfo.nickName)
            this.getLogin(userInfo.nickName)
          }
        });
      },
    });
  },
  // 任务插件保存
   async onSubmit() {
    const res = await plugintask.client.post({ path: "/task/submit" })
  },

    copy(event){//粘贴复制ename
      console.log("复制")
    my.setClipboard({
      text: this.data.tapData[JSON.stringify(event.target.dataset.a)].ename
    });
  },

    //登录
  getLogin(name) {

    const { cloud } = getApp();
    const options = {
      'userNick': name
    };
    cloud.function.invoke('business', options, 'login').then(res => {
      console.log('登陆成功：'+JSON.stringify(res))
      
    })

  },


    navigateToPlugin() {//打开权益管理中心
    my.navigateTo({ url: 'plugin://myPlugin/orightindex-page' });
  },


  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
       // 页面显示
    this.setData({
      tapData:activePar
    })
    console.log('onshow赋值'+this.data.tapData)
    
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
});
